<?php
/**
 * Get Revage rate and get rate count
 * 
 * @package   App_Sample
 * @author    Zuo Fujie <zuo.fujie@evebit.com>
 * @version   $$Id: GetSortClass.php 130 2011-03-18 03:10:02Z cheng.wei $$
 */
class Evebit_View_Helper_GetCityHeader extends Zend_View_Helper_Abstract {
	
	public $data;
	public $cityId;
	public $cityUrl;
	
	public function getCityHeader($displayMenu = null) {
		$this->data = $this->getUrlArray ( $this->view->infoContent );
		$data ['data'] = $this->data;
		$data ['id'] = $this->cityId;
		$data ['cityUrl'] = $this->cityUrl;
		if (isset ( $displayMenu ) && $displayMenu === false) {
			$data ['displayMenu'] = false;
		}
		$content = $this->view->partial ( 'cityHeader.phtml', 'blocks', $data );
		
		return $content;
	}
	
	public function getUrlArray($info, $datas = null) {
		if (is_object($info)){
			$info = $info->getData();
		}
		if (is_array ( $info )) {
			
			$data ['name'] = $info ['name'];
			$data ['type'] = $info ['type'];
			$data ['target_url'] = $info ['type'] . '/' . $info ['target_url'];
			$datas [] = $data;
			$type = isset($info ['own_type'])?$info ['own_type']:$info ['type'];
			if (isset ( $info ['own_sub_type'] )) {
				$data ['name'] = ucfirst ( $info ['own_sub_type'] );
				$data ['type'] = 'info_thirdType';
				$data ['target_url'] = 'information/city/'.$type.'-list/search/' . $info ['own_sub_type'] . '/id/';
				$datas [] = $data;
			}
			if ($info ['type'] != 'city' && $info ['type'] != 'province') {
				$data ['name'] = $info ['type'];
				$data ['type'] = $info ['type'];
				$data ['target_url'] = 'information/city/'.$type.'-list/search/' . $info ['type'] . '/id/';
				$datas [] = $data;
			}
			
			if (isset ( $info ['own_type'] )) {
				$data ['name'] = $info ['own_type'];
				$data ['type'] = 'info_subtype';
				$data ['target_url'] = 'information/city/'.$type.'-list/search/' . $info ['own_type'] . '/id/';
				$datas [] = $data;
			}
			$j = null;
			foreach ( $info as $key => $item ) {
				if ($key == 'type' && $item == 'city') {
					$this->cityId = $info ['id'];
					$this->cityUrl = $info ['target_url'];
				}
				if (is_array ( $item ) && count ( $item ) > 1) {
					return self::getUrlArray ( $item, $datas );
				} else {
					$j ++;
				}
			}
			if ($j == count ( $info )) {
				//$this->data = array_reverse ( $datas );
				return array_reverse ( $datas );
			}
		}
	
	}

}